

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/icon.png">
  <link rel="icon" href="/img/icon.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="d-lue">
  <meta name="keywords" content="">
  
    <meta name="description" content="JSX：为react简化创建虚拟DOM，本质是object对象（一般对象） 三大属性： state: 值是对象、不能直接修改（setState） 123456789101112&amp;lt;script type=&amp;quot;text/babel&amp;quot;&amp;gt;    class Demo extends React.Component&amp;#123;        state = &amp;#">
  
  
    <meta name="referrer" content="no-referrer-when-downgrade">
  
  
  <title>React笔记（一） - d-lue&#39; blog</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"dl_coisini.gitee.io","root":"/","version":"1.9.4","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":true,"follow_dnt":true,"baidu":"9c32ca7145bad202032b544e8bf27d19","google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  

  
    <!-- Baidu Analytics -->
    <script async>
      if (!Fluid.ctx.dnt) {
        var _hmt = _hmt || [];
        (function() {
          var hm = document.createElement("script");
          hm.src = "https://hm.baidu.com/hm.js?9c32ca7145bad202032b544e8bf27d19";
          var s = document.getElementsByTagName("script")[0];
          s.parentNode.insertBefore(hm, s);
        })();
      }
    </script>
  

  

  

  

  

  

  



  
<meta name="generator" content="Hexo 6.3.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>d-lue&#39;s blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                <span>标签</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                <span>关于</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/bg/wenzhang.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="React笔记（一）"></span>
          
        </div>

        
          
  <div class="mt-3">
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2023-08-29 12:55" pubdate>
          2023年8月29日 下午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          7.7k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          65 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">React笔记（一）</h1>
            
            
              <div class="markdown-body">
                
                <!-- 官网地址 -->

<script src="https://unpkg.com/react@17/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@17/umd/react-dom.development.js" crossorigin></script>
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>



<p>JSX：为react简化创建虚拟DOM，本质是object对象（一般对象）</p>
<p>三大属性：</p>
<p>state: 值是对象、不能直接修改（setState）</p>
<figure class="highlight scala"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs scala">&lt;script <span class="hljs-class"><span class="hljs-keyword">type</span></span>=<span class="hljs-string">&quot;text/babel&quot;</span>&gt;<br>    <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Demo</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">React</span>.<span class="hljs-title">Component</span></span>&#123;<br>        state = &#123;flag:<span class="hljs-literal">true</span>,res:<span class="hljs-string">&quot;12&quot;</span>&#125;<br>        demoClick = ()=&gt;&#123;<br>            <span class="hljs-keyword">this</span>.setState(&#123;flag : !<span class="hljs-keyword">this</span>.state.flag&#125;)<br>        &#125;<br>        render()&#123;<br>            <span class="hljs-keyword">return</span> &lt;h1 onClick=&#123;<span class="hljs-keyword">this</span>.demoClick&#125;&gt;&#123;<span class="hljs-keyword">this</span>.state.flag ? <span class="hljs-string">&quot;123&quot;</span> : <span class="hljs-string">&quot;456&quot;</span>&#125;&lt;/h1&gt;<br>        &#125;<br>    &#125;<br>    <span class="hljs-type">ReactDOM</span>.render(&lt;<span class="hljs-type">Demo</span>/&gt;,document.getElementById(<span class="hljs-string">&quot;root&quot;</span>))<br>&lt;/script&gt;<br></code></pre></td></tr></table></figure>

<p>props：只读</p>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-keyword">let</span> obj = &#123;<br><span class="hljs-attr">name</span>:<span class="hljs-string">&quot;123&quot;</span>,<br><span class="hljs-attr">age</span>:<span class="hljs-number">15</span><br>&#125;<br><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(...obj) <span class="hljs-comment">// 报错，展开运算符不能展开对象</span><br><br><span class="hljs-keyword">var</span> obj1 = &#123; <span class="hljs-attr">foo</span>: <span class="hljs-string">&quot;bar&quot;</span>, <span class="hljs-attr">x</span>: <span class="hljs-number">42</span> &#125;;<br><span class="hljs-keyword">var</span> obj2 = &#123; <span class="hljs-attr">foo</span>: <span class="hljs-string">&quot;baz&quot;</span>, <span class="hljs-attr">y</span>: <span class="hljs-number">13</span> &#125;;<br><span class="hljs-keyword">var</span> clonedObj = &#123; ...obj1 &#125;;<br><span class="hljs-comment">// 克隆后的对象：&#123; foo: &quot;bar&quot;, x: 42 &#125;</span><br><span class="hljs-keyword">var</span> mergedObj = &#123; ...obj1, ...obj2 &#125;;<br><span class="hljs-comment">// 合并后的对象：&#123; foo: &quot;baz&quot;, x: 42, y: 13 &#125;</span><br><br><span class="hljs-comment">// 复制对象时更改其属性 (合并)</span><br><span class="hljs-keyword">let</span> obj3 = &#123;...obj1,<span class="hljs-attr">foo</span>:<span class="hljs-string">&quot;123&quot;</span>&#125;<br><span class="hljs-comment">// &#123; foo: &quot;123&quot;, x: 42 &#125;</span><br><br><br>&lt;script <span class="hljs-keyword">type</span>=<span class="hljs-string">&quot;text/babel&quot;</span>&gt;<br>    <span class="hljs-keyword">class</span> <span class="hljs-title class_">Demo</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_ inherited__">React.Component</span> &#123;<br>        <span class="hljs-title function_">render</span>(<span class="hljs-params"></span>) &#123;<br>            <span class="hljs-keyword">return</span> (<br>                <span class="language-xml"><span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span></span><br><span class="language-xml">                    <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>&#123;this.props.name&#125;<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span></span><br><span class="language-xml">                    <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>&#123;this.props.sex&#125;<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span></span><br><span class="language-xml">                    <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>&#123;this.props.age&#125;<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span></span><br><span class="language-xml">                <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span></span><br>            )<br>        &#125;<br>    &#125;<br>    <span class="hljs-comment">// Demo.propTypes=&#123;</span><br>    <span class="hljs-comment">//     name:PropTypes.string.isRequired,// 限制字符串、必传</span><br>    <span class="hljs-comment">//      sex:PropTypes.string</span><br>    <span class="hljs-comment">// &#125;</span><br><br>    <span class="hljs-comment">// Demo.defaultProps = &#123;</span><br>    <span class="hljs-comment">//     name: &quot;默认值&quot; // 指定默认值</span><br>    <span class="hljs-comment">// &#125;</span><br><br>    <span class="hljs-keyword">const</span> person = &#123;<br>        <span class="hljs-attr">name</span>: <span class="hljs-string">&quot;&quot;</span>,<br>        <span class="hljs-attr">sex</span>: <span class="hljs-string">&quot;男&quot;</span>,<br>        <span class="hljs-attr">age</span>: <span class="hljs-number">0</span><br>    &#125;<br>    <span class="hljs-title class_">ReactDOM</span>.<span class="hljs-title function_">render</span>(<span class="language-xml"><span class="hljs-tag">&lt;<span class="hljs-name">Demo</span> &#123;<span class="hljs-attr">...person</span>&#125; /&gt;</span></span>, <span class="hljs-variable language_">document</span>.<span class="hljs-title function_">getElementById</span>(<span class="hljs-string">&quot;root2&quot;</span>))<br>&lt;/script&gt;<br></code></pre></td></tr></table></figure>

<p>refs：</p>
<figure class="highlight verilog"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs verilog"><span class="hljs-comment">//1.字符串形式（不推荐）</span><br>&lt;<span class="hljs-keyword">input</span> <span class="hljs-keyword">ref</span>=<span class="hljs-string">&quot;inp&quot;</span>/&gt;<br><span class="hljs-comment">//2.回调形式</span><br><span class="hljs-comment">//(1)内联</span><br>&lt;<span class="hljs-keyword">input</span> <span class="hljs-keyword">ref</span>=&#123;(currentNode)=&gt;&#123;<span class="hljs-keyword">this</span><span class="hljs-variable">.input1</span> = currentNode&#125;&#125; <span class="hljs-keyword">type</span>=<span class="hljs-string">&quot;text&quot;</span> /&gt; <span class="hljs-comment">// currentNode就是input节点</span><br><span class="hljs-comment">// (2)ref回调函数定义成class的绑定函数</span><br>saveInput(c)&#123;<br>    <span class="hljs-keyword">this</span><span class="hljs-variable">.input1</span> = c<br>&#125;<br>&lt;<span class="hljs-keyword">input</span> <span class="hljs-keyword">ref</span>=&#123;<span class="hljs-keyword">this</span><span class="hljs-variable">.saveInput</span>&#125; <span class="hljs-keyword">type</span>=<span class="hljs-string">&quot;text&quot;</span> /&gt;<br><span class="hljs-comment">//3.createRef(最新)</span><br>myRef = React<span class="hljs-variable">.createRef</span>() <span class="hljs-comment">// React.createRef()返回一个被ref标识的节点的容器（该容器只能“专人专用”）</span><br>&lt;<span class="hljs-keyword">input</span> <span class="hljs-keyword">ref</span>=&#123;<span class="hljs-keyword">this</span><span class="hljs-variable">.myRef</span>&#125; <span class="hljs-keyword">type</span>=<span class="hljs-string">&quot;text&quot;</span> /&gt; <span class="hljs-comment">// input被存入这个容器</span><br></code></pre></td></tr></table></figure>



<p>函数柯里化</p>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-comment">/*</span><br><span class="hljs-comment">高阶函数： </span><br><span class="hljs-comment">1.接收的参数是一个函数</span><br><span class="hljs-comment">2.调用的返回值是一个函数</span><br><span class="hljs-comment">常见的高阶函数：Promise、setTimeout、arr.map....</span><br><span class="hljs-comment">函数的柯里化：通过函数调用继续返回函数的方式，实现多次接收参数最后同一处理的函数编码形式</span><br><span class="hljs-comment">*/</span><br>savaFormData = <span class="hljs-function">(<span class="hljs-params">dataType</span>) =&gt;</span> &#123;<br>	<span class="hljs-keyword">return</span> <span class="hljs-function">(<span class="hljs-params">e</span>)=&gt;</span>&#123;<br>		<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(e,dataType)<br>		<span class="hljs-variable language_">this</span>.<span class="hljs-title function_">setState</span>(&#123;[dataType]:e.<span class="hljs-property">target</span>.<span class="hljs-property">value</span>&#125;) <span class="hljs-comment">// 需要用对象“[]”写法读取</span><br>	&#125;	<br>&#125;<br><br>&lt;input onChange=&#123;<span class="hljs-variable language_">this</span>.<span class="hljs-title function_">savaFormData</span>(<span class="hljs-string">&quot;username&quot;</span>)&#125; <span class="hljs-keyword">type</span>=<span class="hljs-string">&quot;text&quot;</span> name=<span class="hljs-string">&quot;name&quot;</span>/&gt;  <span class="hljs-comment">// 把函数的返回值最为回调，如果返回值为函数，则可以拿到e</span><br><span class="language-xml"><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">onChange</span>=<span class="hljs-string">&#123;this.savaFormData&#125;</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;name&quot;</span>/&gt;</span></span>   <span class="hljs-comment">// 把函数作为回调，直接拿到e</span><br></code></pre></td></tr></table></figure>

<p>上述“input”例子不用柯里化实现：</p>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-comment">// 把箭头函数的返回值作为回调，返回值还是个函数</span><br>&lt;input onChange=&#123;<span class="hljs-function">(<span class="hljs-params">e</span>)=&gt;</span>&#123;<span class="hljs-variable language_">this</span>.<span class="hljs-title function_">savaFormData</span>(<span class="hljs-string">&quot;username&quot;</span>,e)&#125;&#125; <span class="hljs-keyword">type</span>=<span class="hljs-string">&quot;text&quot;</span> name=<span class="hljs-string">&quot;name&quot;</span>/&gt;<br></code></pre></td></tr></table></figure>



<p>生命周期：</p>
<img src="C:\Users\dinglue\AppData\Roaming\Typora\typora-user-images\image-20230817143601606.png" srcset="/img/loading.gif" lazyload alt="image-20230817143601606" style="zoom: 67%;" /> 

<figure class="highlight reasonml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs reasonml">旧：<br>constructor: 构造器<br>componentWillMount：组件将要挂载<br>render:渲染，调用时机初始化渲染、状态更新之后     **常用**<br>componentDidMount（mounted）：组件挂载页面之后    **常用**<br>componentWillUnmount：组件卸载之前   **常用**<br><span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">ReactDOM</span>.</span></span>unmount<span class="hljs-constructor">ComponentAtNode(<span class="hljs-params">document</span>.<span class="hljs-params">getElementById</span>(<span class="hljs-string">&quot;root&quot;</span>)</span>) <span class="hljs-comment">//销毁 触发componentWillUnmount钩子</span><br>shouldComponentUpdate：控制组件更新的“阀门” 如果没写 react自动补且返回<span class="hljs-literal">true</span> 如果写必须返回<span class="hljs-literal">true</span> <span class="hljs-keyword">or</span> <span class="hljs-literal">false</span><br>componentWillUpdate：组件将要更新<br>componentDidUpdate：组件更新之后<br>componentWillReceiveProps： 组件将要接收参数时调用，可以接收到参数 props（第一次传递的参数不调用）<br><br>setState：更新状态中的数据 this.set<span class="hljs-constructor">State(&#123;&#125;)</span><br>forceUpdate：不更改任何状态中的数据，强制更新 this.force<span class="hljs-constructor">Update()</span><br></code></pre></td></tr></table></figure>

<img src="C:\Users\dinglue\AppData\Roaming\Typora\typora-user-images\image-20230817150802006.png" srcset="/img/loading.gif" lazyload alt=" " style="zoom:50%;" /> 





<figure class="highlight pf"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs pf">新旧对比：<br>废弃三个钩子 --- componentWillMount、componentWillReceiveProps、componentWillUpdate<br>新增两个钩子：不常用 (基本不用)<br>getDerivedStateFormProps 配合 static使用 返回状态对象<br>// 若<span class="hljs-keyword">state</span>的值在任何时候都取决于props，那么可以使用<br>static getDerivedStateFormProps(props,<span class="hljs-keyword">state</span>)&#123;<br>	.....<br>	return props<br>&#125;<br>getSnapshotBeforeUpdate()&#123;&#125;<br><br><br><br>render:渲染，调用时机初始化渲染、状态更新之后     **常用**<br>componentDidMount（mounted）：组件挂载页面之后    **常用**<br>componentWillUnmount：组件卸载之前   **常用**<br></code></pre></td></tr></table></figure>

<p>新：</p>
<img src="C:\Users\dinglue\AppData\Roaming\Typora\typora-user-images\image-20230817170817887.png" srcset="/img/loading.gif" lazyload alt="image-20230817170817887" style="zoom:67%;" /> 





<p>react脚手架</p>
<figure class="highlight dsconfig"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs dsconfig"><span class="hljs-built_in">create-react-app</span> <span class="hljs-string">name</span><br></code></pre></td></tr></table></figure>



<p>react ajax</p>
<figure class="highlight ebnf"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs ebnf"><span class="hljs-attribute">axios</span><br></code></pre></td></tr></table></figure>

<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><code class="hljs js">proxy配置代理:<br>在src下创建配置文件：src/setupProxy.<span class="hljs-property">js</span>:<br><span class="hljs-keyword">const</span> &#123; createProxyMiddleware &#125; = <span class="hljs-built_in">require</span>(<span class="hljs-string">&#x27;http-proxy-middleware&#x27;</span>);<br> <br><span class="hljs-variable language_">module</span>.<span class="hljs-property">exports</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">app</span>) &#123;<br>  app.<span class="hljs-title function_">use</span>(<br>    <span class="hljs-title function_">createProxyMiddleware</span>(<span class="hljs-string">&#x27;/api1&#x27;</span>, &#123;<br>      <span class="hljs-attr">target</span>: <span class="hljs-string">&#x27;http://localhost:5000&#x27;</span>,<br>      <span class="hljs-attr">changeOrigin</span>: <span class="hljs-literal">true</span>,<br>      <span class="hljs-attr">pathRewrite</span>: &#123;<span class="hljs-string">&#x27;^/api1&#x27;</span>: <span class="hljs-string">&#x27;&#x27;</span>&#125;<br>    &#125;),<br>    <span class="hljs-title function_">createProxyMiddleware</span>(<span class="hljs-string">&#x27;/api2&#x27;</span>, &#123;<br>      <span class="hljs-attr">target</span>: <span class="hljs-string">&#x27;http://localhost:5001&#x27;</span>,<br>      <span class="hljs-attr">changeOrigin</span>: <span class="hljs-literal">true</span>,<br>      <span class="hljs-attr">pathRewrite</span>: &#123;<span class="hljs-string">&#x27;^/api2&#x27;</span>: <span class="hljs-string">&#x27;&#x27;</span>&#125;<br>    &#125;)<br>  );<br>&#125;;<br></code></pre></td></tr></table></figure>



<p>消息订阅与发布：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-comment">//接收数据的订阅（subscribe），发送数据的发布（publish）</span><br><span class="hljs-comment">//下载: npm install pubsub-js --save</span><br><span class="hljs-comment">//使用: </span><br><span class="hljs-keyword">import</span> <span class="hljs-title class_">PubSub</span> <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;pubsub-js&#x27;</span> <span class="hljs-comment">//引入</span><br><span class="hljs-title class_">PubSub</span>.<span class="hljs-title function_">subscribe</span>(<span class="hljs-string">&#x27;delete&#x27;</span>, <span class="hljs-keyword">function</span>(<span class="hljs-params">fnName,data</span>)&#123; &#125;); <span class="hljs-comment">//订阅</span><br><span class="hljs-title class_">PubSub</span>.<span class="hljs-title function_">publish</span>(<span class="hljs-string">&#x27;delete&#x27;</span>, data) <span class="hljs-comment">//发布消息</span><br><br></code></pre></td></tr></table></figure>



<p>fetch:</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-comment">//先联系服务器，再接收数据</span><br><span class="hljs-comment">//1)	GET请求</span><br><span class="hljs-title function_">fetch</span>(url).<span class="hljs-title function_">then</span>(<span class="hljs-keyword">function</span>(<span class="hljs-params">response</span>) &#123;<br>    <span class="hljs-keyword">return</span> response.<span class="hljs-title function_">json</span>()<br>  &#125;).<span class="hljs-title function_">then</span>(<span class="hljs-keyword">function</span>(<span class="hljs-params">data</span>) &#123;<br>    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(data)<br>  &#125;).<span class="hljs-title function_">catch</span>(<span class="hljs-keyword">function</span>(<span class="hljs-params">e</span>) &#123;<br>    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(e)<br>  &#125;);<br><br><span class="hljs-comment">//2)	POST请求</span><br>  <span class="hljs-title function_">fetch</span>(url, &#123;<br>    <span class="hljs-attr">method</span>: <span class="hljs-string">&quot;POST&quot;</span>,<br>    <span class="hljs-attr">body</span>: <span class="hljs-title class_">JSON</span>.<span class="hljs-title function_">stringify</span>(data),<br>  &#125;).<span class="hljs-title function_">then</span>(<span class="hljs-keyword">function</span>(<span class="hljs-params">data</span>) &#123;<br>    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(data)<br>  &#125;).<span class="hljs-title function_">catch</span>(<span class="hljs-keyword">function</span>(<span class="hljs-params">e</span>) &#123;<br>    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(e)<br>  &#125;)<br><br></code></pre></td></tr></table></figure>



<p>SPA</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-number">1.</span>	单页<span class="hljs-title class_">Web</span>应用（single page web application，<span class="hljs-variable constant_">SPA</span>）。<br><span class="hljs-number">2.</span>	整个应用只有一个完整的页面。<br><span class="hljs-number">3.</span>	点击页面中的链接不会刷新页面，只会做页面的局部更新。<br><span class="hljs-number">4.</span>	数据都需要通过ajax请求获取, 并在前端异步展现。<br></code></pre></td></tr></table></figure>



<p>路由：</p>
<figure class="highlight ebnf"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs ebnf"><span class="hljs-attribute">react-router-dom</span><br></code></pre></td></tr></table></figure>

<p>路由组件与一般组件</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs xml">1.写法不同：<br>一般：<span class="hljs-tag">&lt;<span class="hljs-name">Demo</span> /&gt;</span><br>路由：<span class="hljs-tag">&lt;<span class="hljs-name">Route</span> <span class="hljs-attr">path</span>=<span class="hljs-string">&quot;/demo&quot;</span> <span class="hljs-attr">component</span>=<span class="hljs-string">&#123;Demo&#125;/</span>&gt;</span><br><br>2.存放位置不同<br>一般：components<br>路由:pages<br><br>3.接收到的props不同：<br>一般：写组件标签传递什么就能收到什么<br>路由：3个固定属性<br>     history<br>     location<br>     match<br></code></pre></td></tr></table></figure>

<p>NavLink:</p>
<figure class="highlight jsx"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs jsx">&lt;<span class="hljs-title class_">NavLink</span> activeClassNmae=<span class="hljs-string">&quot;active&quot;</span> className=<span class="hljs-string">&quot;list-group-item&quot;</span> to=<span class="hljs-string">&quot;/home&quot;</span>&gt;home&lt;/<span class="hljs-title class_">NavLink</span>&gt;<br></code></pre></td></tr></table></figure>



<p>路由组件传参：</p>
<figure class="highlight jsx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs jsx"><span class="hljs-comment">// 传递params参数：</span><br>&#123;<span class="hljs-comment">/* 向路由组件传递params参数 */</span>&#125;<br>&lt;<span class="hljs-title class_">Link</span> to=&#123;<span class="hljs-string">`/home/message/detail/<span class="hljs-subst">$&#123;item.id&#125;</span>/<span class="hljs-subst">$&#123;item.title&#125;</span>`</span>&#125; &gt;&#123;item.<span class="hljs-property">title</span>&#125;&lt;/<span class="hljs-title class_">Link</span>&gt;<br><br>&#123;<span class="hljs-comment">/* 声明接收params参数 */</span>&#125;<br>&lt;<span class="hljs-title class_">Route</span> path=<span class="hljs-string">&quot;/home/message/detail/:id/:title&quot;</span> component=&#123;<span class="hljs-title class_">Detail</span>&#125;&gt;&lt;/<span class="hljs-title class_">Route</span>&gt;<br><br>&#123;<span class="hljs-comment">/* 接收params参数 */</span>&#125;<br><span class="hljs-keyword">const</span> &#123;id,title&#125; = <span class="hljs-variable language_">this</span>.<span class="hljs-property">props</span>.<span class="hljs-property">match</span>.<span class="hljs-property">params</span><br></code></pre></td></tr></table></figure>

<figure class="highlight jsx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs jsx"><span class="hljs-comment">//传递search参数（query）：</span><br>&#123;<span class="hljs-comment">/* 向路由组件传递search参数 */</span>&#125;<br>&lt;<span class="hljs-title class_">Link</span> to=&#123;<span class="hljs-string">`/home/message/detail?id=<span class="hljs-subst">$&#123;item.id&#125;</span>&amp;title=<span class="hljs-subst">$&#123;item.title&#125;</span>`</span>&#125; &gt;&#123;item.<span class="hljs-property">title</span>&#125;&lt;/<span class="hljs-title class_">Link</span>&gt;<br><br>&#123;<span class="hljs-comment">/* 无需声明接收params参数 */</span>&#125;<br>&lt;<span class="hljs-title class_">Route</span> path=<span class="hljs-string">&quot;/home/message/detail&quot;</span> component=&#123;<span class="hljs-title class_">Detail</span>&#125;&gt;&lt;/<span class="hljs-title class_">Route</span>&gt;<br><br>&#123;<span class="hljs-comment">/* 接收search参数 */</span>&#125;<br><span class="hljs-keyword">const</span> &#123;search&#125; = <span class="hljs-variable language_">this</span>.<span class="hljs-property">props</span>.<span class="hljs-property">location</span><br><span class="hljs-comment">//需借助querystring解码</span><br></code></pre></td></tr></table></figure>

<figure class="highlight jsx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs jsx"><span class="hljs-comment">//传递state参数（路由独有的）</span><br>&#123;<span class="hljs-comment">/* 向路由组件传递state参数 */</span>&#125;<br>&lt;<span class="hljs-title class_">Link</span> to=&#123;&#123;<span class="hljs-attr">pathname</span>:<span class="hljs-string">&quot;/home/message/detail&quot;</span>,<span class="hljs-attr">state</span>:&#123;<span class="hljs-attr">id</span>:item.<span class="hljs-property">id</span>,<span class="hljs-attr">title</span>:item.<span class="hljs-property">title</span>&#125;&#125;&#125; &gt;&#123;item.<span class="hljs-property">title</span>&#125;&lt;/<span class="hljs-title class_">Link</span>&gt;<br><br>&#123;<span class="hljs-comment">/* 无需声明接收state参数 */</span>&#125;<br>&lt;<span class="hljs-title class_">Route</span> path=<span class="hljs-string">&quot;/home/message/detail&quot;</span> component=&#123;<span class="hljs-title class_">Detail</span>&#125;&gt;&lt;/<span class="hljs-title class_">Route</span>&gt;<br><br>&#123;<span class="hljs-comment">/* 接收state参数 */</span>&#125;<br><span class="hljs-keyword">const</span> &#123;id,title&#125; = <span class="hljs-variable language_">this</span>.<span class="hljs-property">props</span>.<span class="hljs-property">location</span>.<span class="hljs-property">state</span> || &#123;&#125;<br><br></code></pre></td></tr></table></figure>



<p>编程式路由：</p>
<figure class="highlight jsx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs jsx"><span class="hljs-comment">// 传递params参数：</span><br><span class="hljs-variable language_">this</span>.<span class="hljs-property">props</span>.<span class="hljs-property">history</span>.<span class="hljs-title function_">push</span>(<span class="hljs-string">`/home/message/detail/<span class="hljs-subst">$&#123;id&#125;</span>/<span class="hljs-subst">$&#123;title&#125;</span>`</span>)<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">props</span>.<span class="hljs-property">history</span>.<span class="hljs-title function_">replace</span>(<span class="hljs-string">`/home/message/detail/<span class="hljs-subst">$&#123;id&#125;</span>/<span class="hljs-subst">$&#123;title&#125;</span>`</span>)<br><br><span class="hljs-comment">// 传递search参数（query）：</span><br><span class="hljs-variable language_">this</span>.<span class="hljs-property">props</span>.<span class="hljs-property">history</span>.<span class="hljs-title function_">push</span>(<span class="hljs-string">`/home/message/detail?id=<span class="hljs-subst">$&#123;id&#125;</span>&amp;title=<span class="hljs-subst">$&#123;title&#125;</span>`</span>)<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">props</span>.<span class="hljs-property">history</span>.<span class="hljs-title function_">replace</span>(<span class="hljs-string">`/home/message/detail?id=<span class="hljs-subst">$&#123;id&#125;</span>&amp;title=<span class="hljs-subst">$&#123;title&#125;</span>`</span>)<br><br><span class="hljs-comment">// 接收state参数</span><br><span class="hljs-variable language_">this</span>.<span class="hljs-property">props</span>.<span class="hljs-property">history</span>.<span class="hljs-title function_">push</span>(<span class="hljs-string">`/home/message/detail?id=<span class="hljs-subst">$&#123;id&#125;</span>&amp;title=<span class="hljs-subst">$&#123;title&#125;</span>`</span>,&#123;id,title&#125;)<br><span class="hljs-variable language_">this</span>.<span class="hljs-property">props</span>.<span class="hljs-property">history</span>.<span class="hljs-title function_">replace</span>(<span class="hljs-string">`/home/message/detail?id=<span class="hljs-subst">$&#123;id&#125;</span>&amp;title=<span class="hljs-subst">$&#123;title&#125;</span>`</span>,&#123;id,title&#125;)<br></code></pre></td></tr></table></figure>



<p>withRouter（函数）：</p>
<figure class="highlight jsx"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs jsx"><span class="hljs-comment">// 能接收一般组件，加工为路由组件具有的api  返回值是一个新组件</span><br></code></pre></td></tr></table></figure>



<p>BrowserRouter与HashRouter区别：</p>
<figure class="highlight jsx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs jsx"><span class="hljs-number">1.</span>底层原理：<br>	<span class="hljs-title class_">BrowserRouter</span>使用的是<span class="hljs-variable constant_">H5</span>的historyAPI<br>	<span class="hljs-title class_">HashRouter</span>使用的是<span class="hljs-variable constant_">URL</span>的哈希值<br><span class="hljs-number">2.</span>path表现形式：<br>	<span class="hljs-title class_">BrowserRouter</span>没有#<br>	<span class="hljs-title class_">HashRouter</span>有#<br><span class="hljs-number">3.</span>刷新后对路由state参数的影响：<br>	<span class="hljs-title class_">BrowserRouter</span>没影响，state保存在history对象中<br>	<span class="hljs-title class_">HashRouter</span>导致参数丢失<br></code></pre></td></tr></table></figure>


                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/React/" class="category-chain-item">React</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/React/">#React</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>React笔记（一）</div>
      <div>https://dl_coisini.gitee.io/2023/08/29/reactNote1/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>d-lue</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2023年8月29日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2023/09/07/reactNote2/" title="React笔记（二）">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">React笔记（二）</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2023/06/25/%E7%94%9F%E6%B4%BB%E7%AC%94%E8%AE%B0/" title="生活笔记（一）">
                        <span class="hidden-mobile">生活笔记（一）</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
  
    <div class="statistics">
  
  

  
    
      <span id="busuanzi_container_site_pv" style="display: none">
        总访问量 
        <span id="busuanzi_value_site_pv"></span>
         次
      </span>
    
    
      <span id="busuanzi_container_site_uv" style="display: none">
        总访客数 
        <span id="busuanzi_value_site_uv"></span>
         人
      </span>
    
    
  
</div>

  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>

  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"log":false,"model":{"jsonPath":"/live2dw/assets/hijiki.model.json"},"display":{"position":"right","width":150,"height":300},"mobile":{"show":true},"react":{"opacity":0.7}});</script></body>
</html>
